\subsection{hal.c File Reference}
\label{hal_8c}\index{hal.c@{hal.c}}


HAL (Hardware Abstraction Layer).  


{\ttfamily \#include $<$compat/deprecated.h$>$}\par
{\ttfamily \#include $<$config.h$>$}\par
{\ttfamily \#include $<$crypt.h$>$}\par
{\ttfamily \#include $<$hal.h$>$}\par
{\ttfamily \#include $<$eeprom.h$>$}\par
{\ttfamily \#include $<$io.h$>$}\par
{\ttfamily \#include $<$log.h$>$}\par
{\ttfamily \#include $<$string.h$>$}\par
{\ttfamily \#include $<$tools.h$>$}\par
{\ttfamily \#include $<$types.h$>$}\par
\subsubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void {\bf hal\_\-init} (void)
\begin{DoxyCompactList}\small\item\em Initializes the HAL. \item\end{DoxyCompactList}\item 
{\bf iu8} {\bf xeread} ({\bf iu16} addr)
\item 
void {\bf xewrt} ({\bf iu16} addr, {\bf iu8} b)
\item 
{\bf bool} {\bf hal\_\-eeprom\_\-read} ({\bf iu8} $\ast${\bf dst}, {\bf iu16} src, {\bf iu8} len)
\begin{DoxyCompactList}\small\item\em Read data from EEPROM. \item\end{DoxyCompactList}\item 
{\bf bool} {\bf hal\_\-eeprom\_\-write} ({\bf iu16} {\bf dst}, {\bf iu8} $\ast$src, {\bf iu8} len)
\begin{DoxyCompactList}\small\item\em Write data to EEPROM. \item\end{DoxyCompactList}\item 
void {\bf sendbytet0} ({\bf iu8} b)
\item 
{\bf iu8} {\bf recbytet0} (void)
\item 
void {\bf hal\_\-io\_\-sendByteT0} ({\bf iu8} b)
\begin{DoxyCompactList}\small\item\em Send a byte with T=0 error detection and recovery. \item\end{DoxyCompactList}\item 
{\bf iu8} {\bf hal\_\-io\_\-recByteT0} (void)
\begin{DoxyCompactList}\small\item\em Receive a byte with T=0 error detection and recovery. \item\end{DoxyCompactList}\item 
{\bf bool} {\bf hal\_\-rnd\_\-getBlock} ({\bf iu8} $\ast${\bf dst})
\begin{DoxyCompactList}\small\item\em Returns 8 random bytes. \item\end{DoxyCompactList}\end{DoxyCompactItemize}


\subsubsection{Detailed Description}
HAL (Hardware Abstraction Layer). \begin{DoxyParagraph}{Id:}
\doxyref{hal.c}{p.}{hal_8c},v 1.22 2003/03/30 12:42:21 m Exp 
\end{DoxyParagraph}


\subsubsection{Function Documentation}
\index{hal.c@{hal.c}!hal\_\-eeprom\_\-read@{hal\_\-eeprom\_\-read}}
\index{hal\_\-eeprom\_\-read@{hal\_\-eeprom\_\-read}!hal.c@{hal.c}}
\paragraph[{hal\_\-eeprom\_\-read}]{\setlength{\rightskip}{0pt plus 5cm}{\bf bool} hal\_\-eeprom\_\-read (
\begin{DoxyParamCaption}
\item[{{\bf iu8} $\ast$}]{ dst, }
\item[{{\bf iu16}}]{ src, }
\item[{{\bf iu8}}]{ len}
\end{DoxyParamCaption}
)}\hfill\label{hal_8c_ae23736f92fbd6e59f6e67a191e69ecef}


Read data from EEPROM. 

The internal EEPROM begins at address 0, the external EEPROM is located subsequently.


\begin{DoxyParams}{Parameters}
\item[{\em dst}]Pointer to destination area. \item[{\em src}]EEPROM source address. \item[{\em len}]Length of data in bytes.\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
\item[{\em TRUE}]on success. \item[{\em FALSE}]on failure. Error code given in sw. \end{DoxyRetVals}


References eeprom, EEPROM\_\-SIZE, sw\_\-set(), and xeread().

\index{hal.c@{hal.c}!hal\_\-eeprom\_\-write@{hal\_\-eeprom\_\-write}}
\index{hal\_\-eeprom\_\-write@{hal\_\-eeprom\_\-write}!hal.c@{hal.c}}
\paragraph[{hal\_\-eeprom\_\-write}]{\setlength{\rightskip}{0pt plus 5cm}{\bf bool} hal\_\-eeprom\_\-write (
\begin{DoxyParamCaption}
\item[{{\bf iu16}}]{ dst, }
\item[{{\bf iu8} $\ast$}]{ src, }
\item[{{\bf iu8}}]{ len}
\end{DoxyParamCaption}
)}\hfill\label{hal_8c_a19f6e1f1e627521793f250459c5e49b8}


Write data to EEPROM. 

The internal EEPROM begins at address 0, the external EEPROM is located subsequently.


\begin{DoxyParams}{Parameters}
\item[{\em dst}]EEPROM destination address \item[{\em src}]Pointer to source area. \item[{\em len}]Length of data in bytes.\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
\item[{\em TRUE}]on success. \item[{\em FALSE}]on failure. Error code given in sw. \end{DoxyRetVals}


References eeprom, EEPROM\_\-SIZE, sw\_\-set(), and xewrt().

\index{hal.c@{hal.c}!hal\_\-init@{hal\_\-init}}
\index{hal\_\-init@{hal\_\-init}!hal.c@{hal.c}}
\paragraph[{hal\_\-init}]{\setlength{\rightskip}{0pt plus 5cm}void hal\_\-init (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}\hfill\label{hal_8c_af5ea8985a12feedc3ac25fbb50712183}


Initializes the HAL. 

Must be called after each reset. 

References ADM\_\-KEY\_\-LEN, ATR\_\-ADDR, ATR\_\-LEN\_\-ADDR, ATR\_\-MAXLEN, CARD\_\-STATE\_\-ADDR, eeprom, eepromFile, fd\_\-fromCard, fdEepromFile, FS\_\-START\_\-PTR\_\-ADDR, halsend, INT\_\-KEY\_\-LEN, loadEepromFile, PIN\_\-LEN, PORT, PUK\_\-LEN, RAND\_\-STATE\_\-ADDR, RAND\_\-STATE\_\-LEN, SERNUM\_\-ADDR, SERNUM\_\-LEN, TRANSAC\_\-DATA\_\-ADDR, TRANSAC\_\-DATA\_\-LEN, and TRANSAC\_\-STATE\_\-ADDR.

\index{hal.c@{hal.c}!hal\_\-io\_\-recByteT0@{hal\_\-io\_\-recByteT0}}
\index{hal\_\-io\_\-recByteT0@{hal\_\-io\_\-recByteT0}!hal.c@{hal.c}}
\paragraph[{hal\_\-io\_\-recByteT0}]{\setlength{\rightskip}{0pt plus 5cm}{\bf iu8} hal\_\-io\_\-recByteT0 (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}\hfill\label{hal_8c_a6f2a2f946cf90cb7bd613f2c3ada355c}


Receive a byte with T=0 error detection and recovery. 

Currently only 9600 bps at 3.58MHz with direct convention is supported.

\begin{DoxyReturn}{Returns}
This function returns a received byte. There can't be an error, because T=0 tries endlessly to receive a characters. (And if there is really an error, what should SOSSE do with it anyway?) 
\end{DoxyReturn}


References eeprom, eepromFile, fd\_\-fromCard, fd\_\-toCard, fdEepromFile, halsend, recbytet0(), and saveEepromFile.

\index{hal.c@{hal.c}!hal\_\-io\_\-sendByteT0@{hal\_\-io\_\-sendByteT0}}
\index{hal\_\-io\_\-sendByteT0@{hal\_\-io\_\-sendByteT0}!hal.c@{hal.c}}
\paragraph[{hal\_\-io\_\-sendByteT0}]{\setlength{\rightskip}{0pt plus 5cm}void hal\_\-io\_\-sendByteT0 (
\begin{DoxyParamCaption}
\item[{{\bf iu8}}]{ b}
\end{DoxyParamCaption}
)}\hfill\label{hal_8c_a50f4270db8dcf34e7e98f1e2b43d1135}


Send a byte with T=0 error detection and recovery. 

Currently only 9600 bps at 3.58MHz with direct convention is supported.


\begin{DoxyParams}{Parameters}
\item[{\em b}]Byte to send. \end{DoxyParams}


References fd\_\-fromCard, halsend, and sendbytet0().

\index{hal.c@{hal.c}!hal\_\-rnd\_\-getBlock@{hal\_\-rnd\_\-getBlock}}
\index{hal\_\-rnd\_\-getBlock@{hal\_\-rnd\_\-getBlock}!hal.c@{hal.c}}
\paragraph[{hal\_\-rnd\_\-getBlock}]{\setlength{\rightskip}{0pt plus 5cm}{\bf bool} hal\_\-rnd\_\-getBlock (
\begin{DoxyParamCaption}
\item[{{\bf iu8} $\ast$}]{ dst}
\end{DoxyParamCaption}
)}\hfill\label{hal_8c_a4dfdfc55f93a2f674edd64b10e8332ae}


Returns 8 random bytes. 

{\itshape The current AVR implementation does not produce real random numbers, but pseudo random numbers. These are produced by a X9.17 generator modified to use a counter instead of a timer. The state of this PRNG is held at RAND\_\-STATE\_\-ADDR. The start value (at least the key) at this address should be unique for every card.\/}


\begin{DoxyParams}{Parameters}
\item[{\em dst}]Pointer to the destination, where the 8 random bytes should be written.\end{DoxyParams}

\begin{DoxyRetVals}{Return values}
\item[{\em TRUE}]on success. \item[{\em FALSE}]on failure. Error code given in sw.\end{DoxyRetVals}
\begin{DoxyNote}{Note}
There is still a simpler PRNG in the code, which uses 16 bytes RAM and 126 bytes ROM less than the X9.17 generator. 
\end{DoxyNote}


References crypt\_\-enc, hal\_\-eeprom\_\-read(), hal\_\-eeprom\_\-write(), RAND\_\-STATE\_\-ADDR, RAND\_\-STATE\_\-LEN, SERNUM\_\-ADDR, and SERNUM\_\-LEN.

\index{hal.c@{hal.c}!recbytet0@{recbytet0}}
\index{recbytet0@{recbytet0}!hal.c@{hal.c}}
\paragraph[{recbytet0}]{\setlength{\rightskip}{0pt plus 5cm}{\bf iu8} recbytet0 (
\begin{DoxyParamCaption}
\item[{void}]{}
\end{DoxyParamCaption}
)}\hfill\label{hal_8c_a9a3093898ae4cf654a737752e559f198}


Referenced by hal\_\-io\_\-recByteT0().

\index{hal.c@{hal.c}!sendbytet0@{sendbytet0}}
\index{sendbytet0@{sendbytet0}!hal.c@{hal.c}}
\paragraph[{sendbytet0}]{\setlength{\rightskip}{0pt plus 5cm}void sendbytet0 (
\begin{DoxyParamCaption}
\item[{{\bf iu8}}]{ b}
\end{DoxyParamCaption}
)}\hfill\label{hal_8c_a1c1c09f7e82f4ad3d90198d4c0020320}


Referenced by hal\_\-io\_\-sendByteT0().

\index{hal.c@{hal.c}!xeread@{xeread}}
\index{xeread@{xeread}!hal.c@{hal.c}}
\paragraph[{xeread}]{\setlength{\rightskip}{0pt plus 5cm}{\bf iu8} xeread (
\begin{DoxyParamCaption}
\item[{{\bf iu16}}]{ addr}
\end{DoxyParamCaption}
)}\hfill\label{hal_8c_a479e01d268dbe4531acd66486fb03e5e}


Referenced by hal\_\-eeprom\_\-read().

\index{hal.c@{hal.c}!xewrt@{xewrt}}
\index{xewrt@{xewrt}!hal.c@{hal.c}}
\paragraph[{xewrt}]{\setlength{\rightskip}{0pt plus 5cm}void xewrt (
\begin{DoxyParamCaption}
\item[{{\bf iu16}}]{ addr, }
\item[{{\bf iu8}}]{ b}
\end{DoxyParamCaption}
)}\hfill\label{hal_8c_a28b06176b0c2f2b9476a55c18cfaa65d}


Referenced by hal\_\-eeprom\_\-write().

